package application;

import java.io.File;

import utils.config.Config;
import data.CityArea;
import fetch.paginegialle.Fetcher;


public class MainFetcher {
	
	private String OUT_DIR;
	private CityArea AREA;
	private String SEATYP;
	private double [] center = new double[]{7.694914588808752,45.04900806375188};
	
	public static void main(String[] args) throws Exception {
		MainFetcher mf = new MainFetcher();
		mf.fetch();
		System.out.println("Done");
	}
	
	public MainFetcher() {
		
		Config config = new Config(this.getClass().getSimpleName()+".ser"); 
		
		OUT_DIR = (String)config.get("OUT_DIR");
		
		
		
		AREA = new CityArea((String)config.get("AREA_NAME"), 
				   (double[][])config.get("AREA_BBOX"),
				   (String[])config.get("BASE_IN_DIRS"));
		
		SEATYP = (String)config.get("SEATYP");
	}
	
	public void fetch() throws Exception {
		
		double radius = 2520;
		
		//  Create dir OUT_DIR+"/"+AREA.getName()+"/
		new File(OUT_DIR+"/"+AREA.getName()+"/").mkdir();
		
		Fetcher f = new Fetcher();			
	
	    String xml_file = OUT_DIR+"/"+AREA.getName()+"/"+center[1]+"-"+center[0]+"-"+radius+".xml";
		String query = SEATYP+"?lat="+center[1]+"&lon="+center[0]+"&dist="+radius+"&format=xml";	
				
		f.fetch(query,xml_file);
				
			

	}

}
